home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / COMMUNIC / 0132.ZIP / MODEM07.PAS < prev    next >
Pascal/Delphi Source File  |  1985-11-02  |  5KB  |  156 lines

  1. {.PL72}
  2. PROGRAM MODEM07;
  3.  
  4.   CONST
  5.     fnlen    = 12;     (* filename length *)
  6.     dots     = 50;     (* sector counting dots per line *)
  7.     secsiz   = $80;
  8.     datamask = $7F;
  9.     bufsecs  = 128;    (* number of file sectors to buffer *)
  10.     bufsiz   = $3FFF;  (* text and file buffer size 16k *)
  11.     errormax = 10;     (* maximum errors before abort *)
  12.     retrymax = 5;      (* maximum retryes before abort *)
  13.  
  14.     soh      = 1;      (* start of sector character *)
  15.     eot      = 4;      (* end of transmission character *)
  16.     ack      = 6;      (* acknowledge sector transmission *)
  17.     nak      = 21;     (* error in transmission detected *)
  18.     can      = 24;     (* cancel transmission *)
  19.  
  20.     bell     = #7;
  21.     tab      = #9;
  22.     lf       = #10;
  23.     cr       = #13;
  24.     ctrlz    = #26;    (* end of text file character *)
  25.  
  26.     ctrlc    = #3;
  27.     ctrlk    = #11;
  28.     ctrll    = #12;
  29.     ctrlq    = #17;
  30.     ctrlr    = #18;
  31.     ctrls    = #19;
  32.     ctrlv    = #22;
  33.     capture  = ctrlc;  (* toggle text capture *)
  34.     keep     = ctrlk;  (* keep text buffer *)
  35.     literal  = ctrll;  (* send literal character *)
  36.     quit     = ctrlq;  (* quit *)
  37.     receive  = ctrlr;  (* receive file by sectors *)
  38.     send     = ctrls;  (* send file by sectors *)
  39.     view     = ctrlv;  (* view data transferred *)
  40.  
  41.   TYPE
  42.     fntype = string[fnlen];
  43.  
  44.   VAR
  45.     timeout, asciiflag, showrecv, showtrans, bflag, viewflag : boolean;
  46.     kbdata, moddata, viewmode : char;
  47.     txtptr, n : integer;
  48.     txbuff : array [0..bufsiz] of char;
  49.     xmbuff : array [0..bufsiz] of byte;
  50.     capturefile : file;                  (* file of char *)
  51.     xmodemfile : file;                   (* file of byte *)
  52.     cfilename, xfilename : fntype;
  53.  
  54. procedure hexwrite (cc : byte);
  55.   var
  56.     hch, hcl : integer;
  57.   begin
  58.     hch := $30 + ((cc and $F0) div 16);
  59.     if hch > $39 then hch := hch + 7;
  60.     hcl := $30 + (cc and $F);
  61.     if hcl > $39 then hcl := hcl + 7;
  62.     write (#$1B,'l',chr(hch),chr(hcl),#$1B,'m');
  63.   end;
  64.  
  65. {$I INNOCIO.PAS}
  66. {$I SENDCHAR.PAS}
  67. {$I READCHAR.PAS}
  68. {$I SENDFILE.PAS}
  69. {$I READFILE.PAS}
  70. {$I INSTRUCT.PAS }
  71.  
  72.   begin
  73.     asciiflag := false;
  74.     showrecv  := false;
  75.     showtrans := false;
  76.     bflag     := false;
  77.     viewflag  := false;
  78.     timeout   := false;
  79.     txtptr    := 0;
  80.  
  81.     instruct;
  82.     init_modem;
  83.  
  84.   (* the main loop *)
  85.  
  86.     repeat
  87.       kbdata :=getkbdata;
  88.       case kbdata of
  89.         capture : begin
  90.                     bflag := not bflag;
  91.                     write ('Capture ');
  92.                     if bflag then write ('initiated') else write ('terminated');
  93.                     writeln (', ',bufsiz-txtptr,' bytes free.');
  94.                   end;
  95.         keep    : begin
  96.                     if txtptr = 0 then writeln ('Nothing to save.')
  97.                     else
  98.                     begin
  99.                       write ('Save as what file : ');
  100.                       readln (cfilename);
  101.                       assign (capturefile,cfilename);
  102.                       rewrite (capturefile);
  103.                       txbuff[txtptr] := ctrlz;
  104.                       blockwrite(capturefile,txbuff[0],(txtptr div secsiz) + 1);
  105.                       close (capturefile);
  106.                       txtptr := 0;
  107.                     end
  108.                   end;
  109.         receive : begin
  110.                     write ('Receive what file : ');
  111.                     readln (xfilename);
  112.                     readfile (xfilename);
  113.                   end;
  114.         send    : begin
  115.                     write ('Send what file : ');
  116.                     readln (xfilename);
  117.                     sendfile (xfilename);
  118.                   end;
  119.         view    : begin
  120.                     viewflag := not viewflag;
  121.                     if viewflag then
  122.                     begin
  123.                       write ('View as ascii or hex : ');
  124.                       readln (viewmode);
  125.                       write ('Display will be in ');
  126.                       if viewmode in ['a','A'] then writeln ('ascii.') else
  127.                          writeln ('hex.');
  128.                     end;
  129.                   end;
  130.         literal : begin
  131.                     repeat
  132.                       kbdata := getkbdata;
  133.                     until kbdata > #0;
  134.                     modem_output(ord(kbdata));
  135.                   end;
  136.         else
  137.           if kbdata > #0 then modem_output(ord(kbdata));
  138.           if modem_input_ready then
  139.           begin
  140.             moddata := chr(modem_input);
  141.             if (bflag and (txtptr < bufsiz)) then
  142.             begin
  143.               txbuff[txtptr] := moddata;
  144.               txtptr := txtptr + 1;
  145.             end else if bflag then writeln (cr,lf,bell,'Capture buffer overflow');
  146.             write (moddata);
  147.           end;
  148.         end;
  149.     until kbdata = quit;
  150.     hang_up;
  151.   end.
  152. uffer overflow');
  153.             write (moddata);
  154.           end;
  155.         end;
  156.